import fs from 'fs'
import * as brain from 'brain.js'
import { labeledSamples, testSample } from './data'

const net = new brain.NeuralNetwork({
  inputSize: 49,
  hiddenLayers: [49, 7],
  // hiddenLayers: [8, 6],
  outputSize: 3
});

export function demo() {
  console.log('### AI Demo ###')

  console.log('training...')
  net.train(labeledSamples, {
    errorThresh: 0.0005,
    learningRate: 0.6,
    log: detail => console.log(detail)
  });
  console.log('done')

  console.log('running...')
  const output = net.run(testSample);
  console.log('done')
  console.log(output)

  console.log('thinking...')
  const result = brain.likely(testSample, net);
  console.log('done')
  console.log('result', result)

  const svg = brain.utilities.toSVG(net)
  fs.writeFile('./net.svg', svg, (err) => {
    if (err) {
      console.error(err);
    }
  });
}

demo()
